﻿/**
* @private
* @license	GNU GPLv2
*
* Copyright (C) 2007  Polly Jex.
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
* MA  02110-1301, USA.
*
* @see	http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/

package com.kirika.data.tda {

	/**
	 * @import
	 */
	
	import com.kirika.data.IIterator;
	import com.kirika.data.tda.AbstractIterator;
	import com.kirika.data.types.Record;
	import com.kirika.utils.TypeUtil;
	
	/**
	 * Modelo abstracto de interacion para objetos.
	 * @author	Polly Jex (pollyjex@emc2zen.com.ar)
	 */
	public class AbstractObjectIterator extends AbstractIterator implements IIterator {
		
		/**
		 * Constructor.
		 * @param	value	Coleccion a iterar.
		 * @param	object	Referencia del Objeto.
		 * @return	AbstractObjectIterator
		 */
		public function AbstractObjectIterator( value:Array ) {
			
			super( value );
			
		}
		
		/**
		 * Retorna la clave actual del puntero.
		 * @return	String
		 */
		public function key():String {
			
			return Record( super.value() ).key;
			
		}
		
		/**
		 * Retorna el valor del siguiente elemento de la coleccion.
		 * @return	*
		 */
		public override function next():* {
			
			return Record( super.ResolveNext() ).value;
			
		}
		
		/**
		 * Retorna el valor del siguiente elemento en la coleccion, pero no altera el puntero de lectura.
		 * @return	*
		 */
		public override function peek():* {
			
			var value:* = super.ResolvePeek();
			return ( ! TypeUtil.isUndefined( value ) ) ? Record( value ).value : value;
			
		}
		
		/**
		 * Remueve y retorna el valor del ultimo elemento retornado de la coleccion.
		 * @return	*
		 */
		public override function remove():* {
			
			var value:* = this.value();
			super.remove();	
			
			return value;
			
		}
		
		/**
		 * Mueve el puntero de lectura al valor especifico y retorna su valor.
		 * @param	value	Posicion del puntero.
		 * @return	*
		 */
		public override function seek( value:int ):* {
			
			super.ResolveSeek( value );
			return this.value();
			
		}
		
		/**
		 * Retorna el valor asociado a la posicion actual del puntero.
		 * @return	*
		 */
		public override function value():* {
			
			return Record( super.value() ).value;
			
		}
		
	}
	
}
